package com.my.controller;


import com.my.bean.*;
import com.my.service.MoenyDetailedService;
import com.my.service.OrderVipService;
import com.my.service.ProductionService;
import com.my.service.RelationProjectService;
import com.my.util.SessionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.sql.SQLException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 产康项目关联映射表 前端控制器
 * </p>
 *
 * @author 张子艺
 * @since 2018-08-29
 */
@Controller
@RequestMapping("/relationProject")
public class RelationProjectController {
    @Autowired
    RelationProjectService relationProjectService;

    @Autowired
    MoenyDetailedService moenyDetailedService;



    @RequestMapping("/insertProjectRelation")
    @ResponseBody
    public String insertProjectRelation(RelationProject relationProject){
        try {
            return  relationProjectService.insertProjectRelation(relationProject);
        } catch (SQLException e) {
            return  "该房间未找到订单。";
        }
    }

    @RequestMapping("/findRelationProject")
    @ResponseBody
    public List<Map<String,Object>>   findRelationProject(HttpSession session){
        boolean admin=false;
        //如果事超级管理员  即可查看所有的房间  判断是否为超级管理员
        if(SessionUtil.getSessionUser(session).getRoles().getRoleValue().equals("9f77d5a8-75c6-4d06-adf9-a37e727d491a")){
            admin=true;
        }
        Long areaid=((User)session.getAttribute("user")).getAreaId();
        List<Map<String,Object>> mapist=relationProjectService.findCount(areaid,admin);
        return  mapist;
    }

    @RequestMapping("/relationProject")
    public String relationProject (){
        return "relactionproject";
    }

    @RequestMapping("addToProjectRelation")
    @ResponseBody
    public String insert(Long projectId){
        return  relationProjectService.insertRelationProject2(projectId);

    }
    /**
     * 根据姓名查询有那些项目 （外部）
     * @param voPage 分页查询
     * @return 返回根据房间id发呢也拆线呢出来的信息
     */
    @RequestMapping("/findProjectByUserName")
    @ResponseBody
    public ResultPage<RelationProject> findProjectByUserName(String userName  ,VoPage voPage,HttpSession session){
        boolean admin=false;
        //如果事超级管理员  即可查看所有的房间  判断是否为超级管理员
        if(SessionUtil.getSessionUser(session).getRoles().getRoleValue().equals("9f77d5a8-75c6-4d06-adf9-a37e727d491a")){
            admin=true;
        }
        Long areaid=((User)session.getAttribute("user")).getAreaId();
        ResultPage<RelationProject> list=relationProjectService.findProjectByUserName(userName,voPage,areaid,admin);

        return list;
    }


    /**
     * 删除产外部康已预约的项目
     * @param id
     * @return
     */
    @RequestMapping("/delete")
    @ResponseBody
    public boolean delete(Long id){
        return relationProjectService.deleteById(id);
    }


}
